package com.example.echoewish.repository.network;
import com.example.echoewish.repository.network.service.ChatService;

import java.net.URI;
import java.net.URISyntaxException;

public class ChatServiceNetWork  {
//   private static final String CHAT_URI="ws://10.0.2.2:8080";
   private static final String CHAT_URI="ws://120.78.170.193:8080";

   private ChatService chatService;
   private Boolean isConnect=false;

   public ChatServiceNetWork(int userId,int otherUserId)
   {
      new Thread()
      {
         @Override
         public void run() {
            URI uri= null;
            try {
               uri = new URI(CHAT_URI+"/chat/"+userId+"/"+otherUserId);
               chatService=new ChatService(uri);
               chatService.connectBlocking();
               isConnect=true;
            } catch (URISyntaxException | InterruptedException e) {
               e.printStackTrace();
            }

         }
      }.start();
   }

   public boolean checkIsConnect()
   {
     return  isConnect;
   }

   public void SendMessage(String msg)
   {
      chatService.send(msg);
   }

   public void closeConnect()
   {
      chatService.close();
   }
}
